package com.xbongbong.paas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

/**
 * 阶段推进器 阶段 自定义工作流触发类型
 * @author 魏荣杰
 *
 */
@Getter
public enum StageWorkflowTriggerTypeEnum {

    /**
     * 阶段到达前
     */
    BEFORE_STAGE(1, "enum.stageWorkflowTriggerTypeEnum.name.beforeStage"),
    /**
     * 阶段推进后
     */
    AFTER_STAGE(2, "enum.stageWorkflowTriggerTypeEnum.name.afterStage")
    ;

    private final Integer code;

    private final String name;

    StageWorkflowTriggerTypeEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public static String getNameByCode(Integer code) {
        for (StageWorkflowTriggerTypeEnum value : StageWorkflowTriggerTypeEnum.values()) {
            if (Objects.equals(code, value.getCode())) {
                return value.getName();
            }
        }
        return null;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }
}
